﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using System.Data;
namespace Skynet.MeshAdministration.Views.MainExamCategory
{    
    public partial class MainExamCategoryView : UserControl , IMainExamCategoryView
    {
        private MainExamCategoryPresenter _Presenter; 
        [Dependency]
        public MainExamCategoryPresenter Presenter {
            get { return this._Presenter; }
            set {
                this._Presenter = value;
                this._Presenter.View = this;
                this.DataContext = value;
            } 
        }
        public MainExamCategoryView()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.Presenter.OnViewReady();  
        }

        private void dgExamCategories_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
         
        }

        private void dgExamCategories_InitializingNewItem(object sender, InitializingNewItemEventArgs e)
        {
            var target = e.NewItem as System.Data.DataRowView;
            if (target != null)
            {
                var row = target.Row as Skynet.MeshFoundation.SkyNetLibraryDataSet.ExamCategoriesRow;
                if (target.IsNew)
                {
                    row.Id = Guid.NewGuid();
                }
            }      
            
        }

        private void dgExamCategories_KeyDown(object sender, KeyEventArgs e)
        {
            
        }

        private void dgExamCategories_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete && this.dgExamCategories.SelectedItem  != null)
            {
                if (MessageBox.Show("Delete this item", "Delete", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    var target = this.dgExamCategories.SelectedItem as System.Data.DataRowView;
                    if (target != null)
                    {
                        var row = target.Row as Skynet.MeshFoundation.SkyNetLibraryDataSet.ExamCategoriesRow;
                        row.Delete();  

                        
                    }          
                }
            }
      
        }
    }
}
